Skip to content

perf(concat): hoist per-token chunk state out of the per-iteration closure#331

Merged
Boshen merged 1 commit into
mainfrom
perf/concat-hoist-state
May 26, 2026
Merged

perf(concat): hoist per-token chunk state out of the per-iteration closure#331
Boshen merged 1 commit into
mainfrom
perf/concat-hoist-state

Conversation

@Boshen
Copy link
Copy Markdown
Member

@Boshen Boshen commented May 25, 2026

Summary

`add_sourcemap`'s per-token loop captured `&mut self` inside the `get_source_id().map(...)` / `get_name_id().map(...)` closures so it could update `token_chunk_prev_source_id` / `token_chunk_prev_name_id` on every iteration. That forced the compiler to round-trip the `prev_*` fields through memory (load, mutate, store via the `self` pointer) for every token rather than keeping them in registers.

Track the running prev values in plain locals, then write them back to `self` once at the end. Also handle the first token separately so the `i == 0` dedup check no longer runs every iteration.

Behavior, including the duplicate-token de-duplication at the concatenation seam, is unchanged.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 25, 2026

Merging this PR will improve performance by 1.97%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 14 untouched benchmarks
⏩ 5 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
add_sourcemap_loop 343.3 µs 336.8 µs +1.92%
from_sourcemaps 325.4 µs 319 µs +2.02%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing perf/concat-hoist-state (3959542) with main (db883f9)

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Boshen Boshen force-pushed the perf/concat-hoist-state branch 2 times, most recently from 15efed1 to a6cbefa Compare May 25, 2026 16:38
…osure

`add_sourcemap`'s per-token loop captured `&mut self` inside the
`get_source_id().map(...)` / `get_name_id().map(...)` closures so it
could update `token_chunk_prev_source_id` / `token_chunk_prev_name_id`
on every iteration. That forced the compiler to round-trip the
prev_* fields through memory (load, mutate, store via the `self`
pointer) for every token rather than keeping them in registers.

Track the running prev values in plain locals, then write them back to
`self` once at the end. Also handle the first token separately so the
`i == 0` dedup check no longer runs every iteration.

Behavior, including the duplicate-token de-duplication at the
concatenation seam, is unchanged.
@Boshen Boshen force-pushed the perf/concat-hoist-state branch from a6cbefa to 3959542 Compare May 26, 2026 01:34
@Boshen Boshen merged commit f9a6387 into main May 26, 2026
8 checks passed
@Boshen Boshen deleted the perf/concat-hoist-state branch May 26, 2026 01:39
@oxc-guard oxc-guard Bot mentioned this pull request May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant